package com.Hsu.blog.service;

import com.Hsu.blog.mapper.BlogInfoMapper;
import com.Hsu.blog.mapper.UserInfoMapper;
import com.Hsu.blog.model.BlogInfo;
import com.Hsu.blog.model.Result;
import com.Hsu.blog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Hsu琛君珩
 * @ClassName:UserService
 * @date 2024-01-24
 * @apiNote
 * @Version: v1.0
 */

@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogInfoMapper blogInfoMapper;

    public UserInfo queryByName(String userName){
        return userInfoMapper.queryByName(userName);
    }

    public UserInfo queryById(Integer userId){
        return userInfoMapper.queryById(userId);
    }

    public UserInfo getAuthorInfo(Integer blogId){
        //1.根据blogId获取userId
        BlogInfo blogInfo=blogInfoMapper.queryById(blogId);
        if(blogInfo==null||blogInfo.getId()<0){
            return null;
        }
        //2.根据userId获取用户信息
        return userInfoMapper.queryById(blogInfo.getUserId());
    }
}
